<template>
	<view class="container">
		<!-- 选择自己工作过的孔号 -->
		<!-- <view class="u-padding-20 white-bg z-b-r u-flex">
			<view class="u-flex-1">
				<u-form :model="form" :border-bottom="false" ref="uForm" label-width="auto">
					<u-form-item label-width="80" required="true" label="孔深" prop="hole_deep">
						<u-input v-model="form.hole_deep" placeholder="请输入孔深(单位/米)" />
					</u-form-item>
				</u-form>
			</view>
			<u-button class='u-margin-20' :disabled="searchBtnDis" type="primary" @click="searchSubmit">查询</u-button>
		</view> -->
		
		<view class="u-padding-20 z-b-r white-bg z-font-lg">
			<view class="wkinfo-item">打卡总天数：{{ jobInfoTJ.signCountDay+ ' 天' ||  0 }}</view>
			<view class="wkinfo-item">钻孔总深（单位/净尺）：{{ jobInfoTJ.drillDeepCount || 0 }}</view>
			<view class="wkinfo-item">实得工资（单位/元）：{{ salaryCount || 0 | $_formattingMoney }}</view>
			<view class="wkinfo-item">实际工资结算方式：{{ jobInfoTJ.salaryWay || "" }}</view>
			<view class="wkinfo-item">钻机工作人数：{{ drillWkNum+ ' 人' || "" }}</view>
			<view class="wkinfo-item">按尺结算标准：{{ projectInfo.salary_standard_chi+' 元/净尺' || "" }}</view>
			<view class="wkinfo-item">按天结算标准：{{ projectInfo.salary_standard_day+' 元/每天' || "" }}</view>
		</view>
		<view class="u-padding-20 z-b-r white-bg u-margin-top-20">
			<view class="z-font-lg u-padding-bottom-20" style="font-weight: bold;border-bottom: 1rpx solid #C0C0C0;">
				工作量信息
			</view>
			<wx-load-more ref="loadMore" @provider="provider" :pageSize="20">
				<template v-slot:list="{ items }">
					<view style="border: 1rpx solid #C0C0C0;">
						<view class="th-head u-flex u-row-around">		
							<view class="th-head-row th-head-row1">孔深</view>
							<view class="th-head-row th-head-row2">孔号</view>
							<view class="th-head-row th-head-row3">打卡日期</view>
							<view class="th-head-row th-head-row4">状态</view>
						</view>
						<view 
						class="td-body u-flex u-row-around" 
						v-for="(item,index) in items" :key="index" 
						>
							<view class="td-body-row td-body-row1">{{ item.hole_deep}}</view>
							<view class="td-body-row td-body-row2">{{ item.hole_mark }}</view>
							<view class="td-body-row td-body-row3">{{ item.date }}</view>
							<view class="td-body-row td-body-row4">
								<u-tag 
									size="mini" 
									:text="item.signinStatus === 1 ? '通过' : (item.signinStatus === 0 ? '待审核' : '未通过')" 
									:type="item.signinStatus === 1 ? 'success' : (item.signinStatus === 0 ? 'info' : 'error')" 
									/>
							</view>
						</view>
					</view>
				</template>
			</wx-load-more>
		</view>
	</view>
</template>

<script>
	import wxLoadMore from '@/components/wx-load-more/wx-load-more.vue';
	import {myMath} from "@/common/mathUtils.js";
	import {mapState} from "vuex";
	export default {
		components: {
			wxLoadMore
		},
		data() {
			return {
				searchBtnDis:false,
				projectID:"",
				projectInfo:{},
				drillWkNum:0,
				workerInfos:[],
				jobInfoTJ:{},
				salaryStandardChi:"",
				salaryStandardDay:"",
				signCountDay:0,
				drillDeepCount:0,
				salaryCount:0,
				wkPersonNum:0
			}
		},
		computed:{
			...mapState({
				token:"token",
				wkID:"wkID"
			})
		},
		onLoad(params) {
			this.projectID = params.projectID;
			this.jobInfoTJ = JSON.parse(decodeURIComponent(params.TJ));
			// console.log(this.jobInfoTJ);
			this.salaryStandardChi = parseFloat(params.C);
			this.salaryStandardDay = parseFloat(params.D);
			this.signCountDay = parseInt(params.day);
			this.drillDeepCount = parseFloat(params.deep);
			this.wkPersonNum = parseInt(params.wks);
			// console.log(this.salaryStandardChi,this.salaryStandardDay,this.signCountDay,this.drillDeepCount,this.wkPersonNum);
			//获取项目信息
			this.getProjectInfo()
		},
		mounted() {
			this.$refs.loadMore.reLoadData();
		},
		onReachBottom() {
			this.$refs.loadMore.reachBottom()
		},
		methods: {
			// 查询自己的工作信息
			// 1、根据孔号和项目id查询打卡记录 ，也就是查询有多少人
			// searchSubmit(){
				
			// },
			async getProjectInfo(){
				let {token,wkID,projectID,jobInfoTJ} = this;
				this.drillWkNum = 0;
				let res = await this.$network({
					api:"main",
					data:{
						action:"projectAdmin/getProjectDetail",
						data:{
							id:projectID
						}
					}
				})

				if(res.status === 0){
					this.projectInfo = res.data[0];
					this.projectInfo.worker_ids.forEach((item,index)=>{
						if(item.drillID === jobInfoTJ.drillID){
							this.drillWkNum += 1;
						}
					})
					
					// 计算价格
					this.salaryCalculator();
				}
			},
			//根据条件计算工资
			salaryCalculator(){
				/**
				 * 按尺结算(米):23.5/米
				 * 按天数结算:198.3/天
				 */
				let {jobInfoTJ,salaryStandardChi,salaryStandardDay,drillWkNum} = this;
				if(jobInfoTJ.salaryWay == '按尺结算'){
					let m = myMath.accMul(jobInfoTJ.drillDeepCount,parseFloat(salaryStandardChi));
					this.salaryCount = myMath.accDiv(m,parseInt(drillWkNum));
				} else if(jobInfoTJ.salaryWay == '按天数结算'){
					let m = myMath.accMul(jobInfoTJ.signCountDay,parseFloat(salaryStandardDay));
					this.salaryCount = myMath.accDiv(m,parseInt(drillWkNum));
				}
			},
			async provider(e) {
				let {token,wkID,projectID} = this;
				let {pageNo,pageSize} = e;
				this.$loading("正在加载")
				
				let res = await this.$network({
					api:"main",
					data:{
						action:"wkProjectAdmin/getWorkerInfo",
						data:{
							token,
							wkID,
							projectID,
							pageNo,
							pageSize
						}
					}
				})
				uni.hideLoading();
				if (res.status === 0) {
					this.$refs.loadMore.pushData(res.data);
				} else if (res.status === 1) {
					this.$refs.loadMore.pushData([]);
				}
			}
		}
	}
</script>

<style scoped>
	.workload{
		line-height: 60rpx;
		text-align: left;
	}
	.td-body-row,
	.th-head-row{
		line-height: 60rpx;
		text-align: center;
	}
	.td-body{
		border-bottom: 1rpx solid #C0C0C0;
	}
	.td-body-row1,
	.th-head-row1,
	.td-body-row2,
	.th-head-row2,
	.td-body-row4,
	.th-head-row4
	{
		width: 20%;
	}
	.td-body-row3,
	.th-head-row3
	{
		width: 40%;
	}
	.th-head{
		font-weight: bold;
		background: #edece8;
		line-height: 80rpx;
		text-align: center;
	}
	.wkinfo-item{
		line-height: 60rpx;
		font-weight: bold;
	}
</style>
